<?php
/**
 * @title 232. 用栈实现队列
 * @author start2004
 */

// ini_set("memory_limit", "128M");

// class Solution {
//
//     function find() {
//
//     }
// }

class MyQueue {
    /**
     */
    function __construct() {
        $this->stack1 = new SplStack();
        $this->stack2 = new SplStack();
    }

    /**
     * @param Integer $x
     * @return NULL
     */
    function push($x) {
        $this->stack1->push($x);
    }

    /**
     * @return Integer
     */
    function pop() {
        /**
         * @return
         */
        $this->RemoveData();
        return $this->stack2->pop();
    }

    /**
     * @return Integer
     */
    function peek() {
        /**
         * @return
         */
        $this->RemoveData();
        return $this->stack2->top();
    }

    /**
     * @return Boolean
     */
    function empty() {
        /**
         * @return
         */
        $this->RemoveData();
        return $this->stack2->isEmpty();
    }

    /**
     * @title 栈1数据转移到栈2
     * @author start2004
     * @since 2024-03-04 Created
     */
    function RemoveData() {
        /**
         * @since 2024-03-04 栈2为空，栈1数据导入栈2
         */
        if($this->stack2->isEmpty()){
            while(!$this->stack1->isEmpty()){
                $this->stack2->push($this->stack1->pop());
            }
        } else {}
    }
}

/**
 * Your MyQueue object will be instantiated and called as such:
 * $obj = MyQueue();
 * $obj->push($x);
 * $ret_2 = $obj->pop();
 * $ret_3 = $obj->peek();
 * $ret_4 = $obj->empty();
 */


/**
 * @url http://127.0.0.1/leetcode/202403/2024.03.04.php
 */
$datas = [

];

include_once dirname(__DIR__) . DIRECTORY_SEPARATOR ."xhprof.php";
$xhprof = new Xhprof();
foreach ($datas as $data){
    /**
     * @since 2024-01-15 超时和错误案例参数
     */
    // $data = $xhprof->FormatArgs("/tmp/leetcode/xxx-xxx.txt");

    // $data[0] = $xhprof->listNode($data[0]);
    // $data[0] = $xhprof->tree($data[0]);
    echo $xhprof->DumpArgs($data);
    echo "\n<hr>\n";

    $obj = new Solution();
    $result = $obj->(...$data);
    echo $xhprof->DumpArgs([$result]);
    var_dump($result);

    echo "\n<hr>". str_repeat("<br>", 2) . str_repeat(PHP_EOL, 5);
}

// foreach ($datas as $data){
//     $obj = new $data[0][0](...$data[1][0]);
//
//     for ($i=1; $i<count($data[0]); $i++){
//         $func = $data[0][$i];
//         $param = $data[1][$i];
//         $result = $obj->$func(...$param);
//
//         echo $data[0][$i] ."(\"". implode(",", $data[1][$i]) ."\") ";
//             if($result === true){
//                 echo "True";
//             } elseif($result === false) {
//                 echo "False";
//             } elseif($result === null) {
//                 echo "Null";
//             } elseif(is_array($result)) {
//                 var_dump($result);
//             } else {
//                 echo $result;
//             }
//         echo PHP_EOL;
//     }
//
//     echo str_repeat(PHP_EOL, 3);
// }
$xhprof->end();
